package com.zhaojiadi.singleton;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Description:
 */
public class Singleton_06 {
    private static final AtomicReference<Singleton_06> INSTANCE=new AtomicReference<>();

    private Singleton_06() {
    }

    public static final Singleton_06 getInstance(){
        while (true){
            Singleton_06 instance = INSTANCE.get();
            if(Objects.nonNull(instance)) return instance;
            INSTANCE.compareAndSet(null,new Singleton_06());
            return INSTANCE.get();
        }
    }

    public static void main(String[] args) {
        System.out.println(Singleton_06.getInstance());
        System.out.println(Singleton_06.getInstance());

    }
}
